import os

# 获取当前项目根路径
def project_root_path(project_name=None, print_log=True):
    p_name = 'company-crawler' if project_name is None else project_name
    project_path = os.path.abspath(os.path.dirname(__file__))
    # Windows
    if project_path.find('\\') != -1: separator = '\\'
    # Mac、Linux、Unix
    if project_path.find('/') != -1: separator = '/'

    root_path = project_path[:project_path.find(f'{p_name}{separator}') + len(f'{p_name}{separator}')]+p_name
    if print_log: print(f'当前项目名称：{p_name}\r\n当前项目根路径：{root_path}')
    return root_path

if __name__ == '__main__':
    project_root_path('company-crawler')